<template>
	<view>
		<view class="flex flex-column p-24r mb-20 bg-white" v-for="(item, index) in list" :key="index">
			<view class="flex justify-between">
				<text class="mb-10 text-18">{{item.date}}
						<text class="text-999 text-14">星期{{getWeekText(item.date)}}</text>
				</text>
			</view>
			<view v-for="(acc,index) in item.list" :key="index" class="detail-item my-10">
				<view class="flex items-center px-12" >
						<text v-if="acc.image==''" style="background-color: gold;font-size: 30px;" class="iconfont p-16r mr-20r rounded-20p" :class="acc.icon"/>
						<image v-else :src="acc.image" class="w-46p h-46p mr-20r rounded-20p" mode="aspectFill"/>
					<view class="flex-auto flex flex-column content-start gap-10px">
						<text>{{acc.title}}</text>
						<text class="text-12" style="color: #999;">{{acc.time}}</text>
					</view>
					<text class="flex-auto text-14 px-6" style="color: #999;">{{acc.remark}}</text>
					<text :class="{'high':acc.type==1}">¥&nbsp;<text v-if="acc.type==0">-</text>{{formatMoney(acc.num)}}</text>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	import {getRankDetail} from '@/api/api.js';
	import {fmtNum,formatMoney} from '@/common/format.js';
	export default {
		data() {
			return {
				list:[]
			}
		},
	  async	onLoad(options) {
		  const {type,type_id,type_title,date_type,date_value} = options
		  const txt = type_title+(type=='1'?'收入':'支出')+'-'+ (date_type=='0'?`${date_value.split('-')[0]}年第${date_value.split('-')[1]}周`:date_type=='1'?`${date_value.split('-')[0]}年${date_value.split('-')[1]}月`:`${date_value}年`)
		  // console.log(txt)
			uni.setNavigationBarTitle({
				title:txt
			})
			const list = await getRankDetail(type_id,date_type,date_value)
			// console.log(JSON.stringify(list))
			const monArr = [],dataList=[]
			// const test = list.filter(listItem => listItem.mon=='01-18')
			// console.log(test)
			for (let item of list) {
				// console.log(monArr.indexOf(item.mon))
				if(monArr.indexOf(item.mon)==-1) {
					monArr.push(item.mon)
					dataList.push({
						date:item.mon,
						list:list.filter(listItem => listItem.mon==item.mon)
					})
				}
			}
			// console.log(dataList)
			this.list = dataList
			
		},
		methods: {
			formatMoney(num) {
				return formatMoney(num)
			},
			getWeekText(mon_date) {
				const weekTxt = ['日','一','二','三','四','五','六']
				// const year = this.datePickerValue.split('-')[0]
				const date = new Date('2024-'+mon_date)
				
				return weekTxt[date.getDay()]
			},
		}
	}
</script>

<style lang="scss">
	.detail-item {
		border-bottom: 2px dashed #eee;
		padding-bottom: 6px;
		&:last-child {
			margin-bottom: 0;
			border: none;
		}
	}
</style>
